package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseReleaseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseReleaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseReleaseLogic {
	return &HouseReleaseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseReleaseLogic) HouseRelease(in *house.HouseReleaseRequest) (*house.HouseReleaseResponse, error) {
	// todo: add your logic here and delete this line
	userId := 1
	h := mysql.House{
		UserId:     int64(userId),
		HouseName:  in.HouseName,
		HousePrice: in.HousePrice,
		Floor:      in.Floor,
		Acreage:    in.Acreage,
		Address:    in.Address,
		HouseType:  in.HouseType,
	}
	err := h.HouseView(int64(h.ID))
	if err != nil {
		logx.Info("房源信息不能为空")
		return nil, errors.New("房源信息不能为空")

	}
	if h.ID != 0 {
		logx.Info("房源信息不能为空")
		return nil, errors.New("房源信息不能为空")
	}
	err = h.Create()
	if err != nil {
		logx.Info("创建发布房源信息失败", err)
		return nil, errors.New("创建发布房源信息失败")
	}
	return &house.HouseReleaseResponse{
		HouseId: int64(h.ID),
	}, nil
}
